import dev from './dev'
import prod from './prod'

export default () => {
    
    function copyConf(target:{[key:string]:any}, source:{[key:string]:any}) {
        for(let k in source) {
            if(k in target) {
                if(typeof source[k] == 'object' && !Array.isArray(source[k])) {
                    copyConf(target[k], source[k])
                }else {
                    target[k] = source[k]
                }
            }else {
				target[k] = source[k]
			}
        }
    }


    const common = {
        loginFailMaxCount : 5,
        
        defaultPassword : '123456',
        pc : 'PC',
        mobile : 'MOBILE',

        white : {
            admin : ['/auth/login', '/lang/list', '/locale', '/lang'],
            userClient : ['/login', '/recharge/notify/:client/:id', '/chargingCard/recharge/notify/:client/:id', '/user/payscore/permissions/:client/:userId']
        },
    
        httpPort : {
            admin : 6000,
            userClient : 6001
        },

        apiPrefix : {
            admin : 'api',
            userClient : 'api',
        },

        jwt : {
            admin : {
                expire : 3600000,
                login : {
                    secret : 'LTAI5tBNbKSkg4rAsqDhvogt',
                    scale : 13,
                },
        
                refreshLogin : {
                    secret : '5KjRP77kbyYN9OxdFdWEvVYmvwrYQe',
                    scale : 355,
                }
            },

            userClient : {
                expire : 3600000,
                login : {
                    secret : 'LTAI5tBNbKSkg4rAsqDhvogt',
                    scale : 13,
                },
        
                refreshLogin : {
                    secret : '5KjRP77kbyYN9OxdFdWEvVYmvwrYQe',
                    scale : 355,
                }
            }
        },

        adminDefaultLoginPwd : '123456',

        wxAccessTokenKey : 'wx:access:token',

        
        startChargeResKey : 'scr:', //开始充电结果
        endChargeResKey : 'ecr:', //结束充电结果
        userChargingOrderKey : 'ucing:', //用户充电中订单
        devicePortChargingKeyReg : 'd:?:p:?', //设备端口充电状态
        deviceIdPortToOrderIdReg : '?:?:oid', //设备id和端口号对应的订单id

        //私人充电的
        PstartChargeResKey : 'p:scr:', //开始充电结果
        PendChargeResKey : 'p:ecr:', //结束充电结果
        PdeviceChargingOrderKey : 'p:dcing:', //设备充电中订单

        aliToDeviceTopicReg : '/?/?/user/alternating/get',
        deviceMsgListKeys : {
            chargeInfo : 'charge:info:list'
        }
    }


    const config = process.env.NODE_ENV == 'dev' ? dev : prod

    copyConf(config, common)
    
    return config

}